﻿namespace Huayou.Common
{
    using Huayou.Utils;
    using System;
    using System.Collections;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CommonBasePage : Page
    {
        private Hashtable m_paramValue = new Hashtable();
        public const string PARAM_NAME = "paramstr";

        public void AddValue(string key, string keyValue)
        {
            if (this.m_paramValue == null)
            {
                this.m_paramValue = new Hashtable();
            }
            if (this.m_paramValue.Contains(key))
            {
                this.m_paramValue.Remove(key);
            }
            this.m_paramValue.Add(key, keyValue);
        }

        public string GetPackStr()
        {
            return HttpUtility.UrlEncode(this.Page.Request.Params["paramstr"]);
        }

        public string GetValue(string key)
        {
            if (this.m_paramValue == null)
            {
                return null;
            }
            if (!this.m_paramValue.Contains(key))
            {
                return null;
            }
            string str = this.m_paramValue[key].ToString();
            if (str.Equals(""))
            {
                return null;
            }
            return str;
        }

        public string PackFull(Hashtable hs)
        {
            return ("paramstr=" + WebUtils.Pack(hs));
        }

        public string PackFull(string pack)
        {
            return ("paramstr=" + pack);
        }

        public string PackPart(Hashtable hs)
        {
            return WebUtils.Pack(hs);
        }

        public static void SetPage(DataGrid dg, IList list)
        {
            DataGridUtils.SetPage(dg, list);
        }

        public static void SetPage(DataGrid dg, DataTable dt)
        {
            DataGridUtils.SetPage(dg, dt);
        }

        public Hashtable UnPack()
        {
            return WebUtils.UnPack(HttpUtility.UrlEncode(this.Page.Request.Params["paramstr"]));
        }

        public Hashtable UnPackFull(string pack)
        {
            return WebUtils.UnPack(pack.Substring(pack.IndexOf("=")));
        }

        public Hashtable UnPackPart(string pack)
        {
            return WebUtils.UnPack(pack);
        }

        public Hashtable ParamValue
        {
            get
            {
                return this.m_paramValue;
            }
            set
            {
                this.m_paramValue = value;
            }
        }
    }
}

